//
//  ZHFTripHeadView.m
//  GoTraveling
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "ZHFTripHeadView.h"

#import "StarView.h"
#import "ZHFAttraction.h"
#import "UIImageView+WebCache.h"
#import "WSTools.h"
#import "ZHFImageView.h"

@interface ZHFTripHeadView ()

@property (nonatomic, retain) UILabel *nameLable;

@property (nonatomic, retain) UILabel *photoCountLable;

@property (nonatomic, retain) UIView *backgView;

@property (nonatomic, retain) UILabel *contentLabel;

@property (nonatomic, retain) StarView *starView;

@property (nonatomic, retain) UILabel *sourceLable;

@property (nonatomic, retain) UIView *lineView;

@property (nonatomic, retain) UILabel *titleLable;

@property (nonatomic, retain) UIColor *color;

@end

@implementation ZHFTripHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"states"] isEqualToString:@"1"]) {
        self.color = [UIColor colorWithRed:0.15 green:0.14 blue:0.16 alpha:1];
    }
    else {
        
        self.color = BACKGRONDCOLOR;
    }
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
    [self addSubview:self.imageView];
    
    self.photoCountLable = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 40, 205, 40, 20)];
    self.photoCountLable.textColor = [UIColor whiteColor];
    self.photoCountLable.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.photoCountLable];
    
    self.backgView = [[UIView alloc] initWithFrame:CGRectMake(0, 230, SCREEN_WIDTH, self.frame.size.height - 290 + 60)];
    self.backgView.backgroundColor = self.color;
    [self addSubview:self.backgView];
    
    self.nameLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, 50)];
    self.nameLable.center = CGPointMake(SCREEN_WIDTH / 2, 30);
    self.nameLable.textAlignment = NSTextAlignmentCenter;
    self.nameLable.font = [UIFont systemFontOfSize:24 weight:0.2];
    self.nameLable.textColor = [UIColor colorWithRed:0.24 green:0.24 blue:0.25 alpha:1];
    if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"states"] isEqualToString:@"1"]) {
        self.nameLable.shadowColor = [UIColor colorWithRed:0.79 green:0.78 blue:0.75 alpha:1];
        self.nameLable.shadowOffset = CGSizeMake(0, 2);
    }
    [self.backgView addSubview:self.nameLable];
    
    self.starView = [[StarView alloc] initWithFrame:CGRectMake(80, 60, self.frame.size.width / 3, 15) number:5];
    [self.backgView addSubview:self.starView];
    
    self.sourceLable = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 + 20, 60, SCREEN_WIDTH / 3, 15)];
    
    self.sourceLable.textColor = [UIColor colorWithRed:0.74 green:0.73 blue:0.71 alpha:1];
    self.sourceLable.font = [UIFont systemFontOfSize:16];
    [self.backgView addSubview:self.sourceLable];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 90, SCREEN_WIDTH - 30 * 2, 60)];
    self.contentLabel.textColor = [UIColor colorWithRed:0.4 green:0.39 blue:0.37 alpha:1];
    self.contentLabel.numberOfLines = 0;
    [self.backgView addSubview:self.contentLabel];
    
    self.lineView = [[UIView alloc] initWithFrame:CGRectMake(50, self.backgView.frame.size.height - 20, SCREEN_WIDTH - 100, 1)];
    [self.backgView addSubview:self.lineView];
    
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 10)];
    self.titleLable.center = CGPointMake(SCREEN_WIDTH / 2, self.lineView.center.y);
    self.titleLable.textColor = [UIColor colorWithRed:0.26 green:0.24 blue:0.19 alpha:1];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    self.titleLable.backgroundColor = self.color;
    self.titleLable.font = [UIFont systemFontOfSize:16];
    [self.backgView addSubview:self.titleLable];
    
}

- (void)setAttraction:(ZHFAttraction *)attraction {

    [self.imageView sd_setImageWithURL:[NSURL URLWithString:attraction.image_url] placeholderImage:[UIImage imageNamed:@"trip_edit_cover_default"]];
    self.photoCountLable.text = [NSString stringWithFormat:@"%ldk", [attraction.photos_count integerValue] / 1000];
    self.nameLable.text = attraction.name_zh_cn;
    [self.starView setStarWithNumber:(NSInteger)[attraction.user_score floatValue]];
    self.sourceLable.text = [NSString stringWithFormat:@"%@分",attraction.user_score];
    self.contentLabel.text = attraction.descriptions;
    
    CGRect frame = self.contentLabel.frame;
    frame.size.height = [WSTools heightForContent:attraction.descriptions size:17];
    self.contentLabel.frame = frame;
    
    self.lineView.backgroundColor = [UIColor colorWithRed:0.84 green:0.83 blue:0.79 alpha:1];
    self.titleLable.text = @"印象";
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
